package cn.hsw.platform.model;

import cn.hsw.platform.core.base.BaseConstant;
import cn.hsw.platform.core.base.BaseModel;
import cn.hsw.platform.core.moudle.setvalue.SetValue;
import cn.hsw.platform.service.RoleService;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.*;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * 用户实体
 *      每个用户可以设置多个角色
 * @author 李子木
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@Table(name = "hsw_manage_user")
@Where(clause = BaseConstant.NOT_DELETE)
@SQLDelete(sql = "update hsw_manage_user" + BaseConstant.DELETE_SQL)
@SQLDeleteAll(sql = "update hsw_manage_user" + BaseConstant.DELETE_SQL)
public class UserModel extends BaseModel implements Serializable {

    private static final long serialVersionUID = 626181545812827281L;

    /**
     * 用户名  8-16位 字母数字
     */
    @JSONField(name = "user_name")
    private String userName;

    /**
     * 手机号
     */
    private String phone;

    /**
     * 密码  加密方式使用BCrypt算法
     */
    @JSONField(serialize = false)
    private String password;

    /**
     * 昵称
     */
    @JSONField(name = "real_name")
    private String realName;

    @Transient
    @JSONField(name = "role_list")
    @SetValue(beanClass = RoleService.class,method = "findByUserPid")
    private List<RoleModel> roleList;
}
